package cn.itsource.ymjs.service.impl;

import cn.itsource.ymjs.config.HighlightResultMapper;
import cn.itsource.ymjs.doc.CourseDoc;
import cn.itsource.ymjs.query.CourseDocQuery;
import cn.itsource.ymjs.repository.CourseDocRepository;
import cn.itsource.ymjs.result.JSONResult;
import cn.itsource.ymjs.result.PageResult;
import cn.itsource.ymjs.service.ICourseDocService;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseDocServiceImpl implements ICourseDocService {

    @Autowired
    private CourseDocRepository repository;

    @Autowired
    private ElasticsearchTemplate template;

    @Autowired
    private HighlightResultMapper highlightResultMapper;

    @Override
    public JSONResult batchAdd(List<CourseDoc> courseDocs) {
        repository.saveAll(courseDocs);
        return JSONResult.success();
    }

    @Override
    public JSONResult batchDel(List<Long> ids) {
        Iterable<CourseDoc> allById = repository.findAllById(ids);
        repository.deleteAll(allById);
        return JSONResult.success();
    }

    @Override
    public PageResult<CourseDoc> queryPageData(CourseDocQuery query) {
//        //1 创建构建器
//        NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder();
//
//        //2 设置查询条件
//        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
//        String keyword = query.getKeyword();
        return null;
    }
}
